﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="EventDetails.aspx.cs" Inherits="VolunteerEventDetails" Title="Event Details" %>
<%@ MasterType virtualpath="~/MasterPage.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <asp:LinqDataSource ID="DSEvents" runat="server" 
        ContextTypeName="OpenGivingDataContext" OrderBy="startTime" 
        TableName="Events" 
        Where="isCancelled == @isCancelled &amp;&amp; event_id == @event_id">
        <WhereParameters>
            <asp:Parameter DefaultValue="false" Name="isCancelled" Type="Boolean" />
            <asp:QueryStringParameter Name="event_id" QueryStringField="event_id" Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>
    
    <ul>
        <li>Indicate/designate which users actually showed up for an event</li>
        <li>Admins can generate check-in sheet for event and update volunteers as attended</li>
    </ul>

    <div style="float: left">
        <asp:ListView ID="ListViewEvent" runat="server" DataSourceID="DSEvents">
            <LayoutTemplate>
                <table>
                    <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td valign="top" style='background-color: Silver; color: Black; font-weight: bold'>
                        <%# Eval("eventName") %> (<%# Eval("event_id") %>)
                    </td>
                </tr>
                <tr>
                    <td>
                        <%# Eval("startTime", "{0:d} {0:t}") %> - <%# Eval("endTime", "{0:t}") %>
                        <br />
                        <%# Eval("address_city") %>
                        <br />
                        <%# Eval("briefDescription") %>
                        <br />
                        Event contact:
                        <%# Eval("UserMappings.lastName")%>,
                        <%# Eval("UserMappings.firstName")%>
                        <br />
                        <%# Int32.Parse(Eval("volunteerMax").ToString()) - GetVolunteerCount(Container.DataItem) %>
                        /
                        <%# Eval("volunteerMax") %>
                        volunteer(s) needed
                        <asp:Button ID="btnVolunteer" Visible='<%# Request.IsAuthenticated && (GetVolunteerCount(Container.DataItem) <= Int32.Parse(Eval("registrationCutOff").ToString())) %>' CommandArgument='<%# Eval("event_id") %>'
                            runat="server" Text="<%# GetVolunteerButtonLabel(Container.DataItem) %>" OnClick="VolunteerButton_Click" />
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
    </div>
    <asp:LinqDataSource ID="DSVolunteers" runat="server" 
        ContextTypeName="OpenGivingDataContext" EnableDelete="True" 
        EnableInsert="True" EnableUpdate="True" TableName="EventRegistrations" 
        Where="event_id == @event_id">
        <WhereParameters>
            <asp:QueryStringParameter Name="event_id" QueryStringField="event_id" 
                Type="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>
    <div style="float: right">
        <asp:LoginView ID="LoginViewVolunteers" runat="server">
            <RoleGroups>
                <asp:RoleGroup Roles="Admin">
                    <ContentTemplate>
                        <div style='background-color: Silver; color: Black; font-weight: bold'>Current volunteers</div>
                        <asp:Repeater ID="rptVolunteers" runat="server" DataSourceID="DSVolunteers" >
                        <HeaderTemplate><table></HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                
                                <td><%# Eval("UserMappings.lastName")%>,
                                <%# Eval("UserMappings.firstName")%></td>
                                <td><asp:CheckBox ID="cbShowedUp" Checked='<%# Eval("attended")%>' Text="Showed up" AutoPostBack="true" OnCheckedChanged="cbShowedUp_CheckedChanged" runat="server" />
                                <asp:HiddenField ID="hfEventInfo" runat="server" Value='<%# Eval("UserMappings.contact_id") + ":" + Eval("Events.event_id")%>' />
                                </td>
                                <td><asp:Button ID="btnRemoveVolunteer" OnClick="btnRemoveVolunteer_Click" CommandArgument='<%# Eval("UserMappings.contact_id") + ":" + Eval("Events.event_id")%>' runat="server" Text="Remove" /></td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate></table></FooterTemplate>
                        </asp:Repeater>
                        <asp:LinkButton ID="LinkButtonSigninSheet" runat="server">Create signin sheet</asp:LinkButton>
                    </ContentTemplate>
                </asp:RoleGroup>
                <asp:RoleGroup Roles="Volunteer">
                </asp:RoleGroup>
            </RoleGroups>
        </asp:LoginView>
    </div>
</asp:Content>
